package khleuven.mondzorg.domain;

import khleuven.mondzorg.Logger;

import org.json.JSONObject;

public class Learn extends ModuleBasedEntry {
	
	private String lesson;
	
	@Deprecated
	public Learn(Language language, DestinationGroup destination, 
			Module module, int seq, String lesson)
			throws DomainException {
		super(EntryType.LEARN, language, destination, module, seq);
		setLesson(lesson);
	}

	public Learn(JSONObject object) throws DomainException {
		super(EntryType.LEARN, object);
		setLesson(JsonKeysDictionary.getStringItem(object, JsonKeysDictionary.JSON_KEY_LEARN_LESSON));
		Logger.logDomain(toString());
	}

	protected String getLesson() {
		return lesson;
	}

	private void setLesson(String lesson) {
		this.lesson = lesson;
	}
	
	@Override
	public String makeStringForList() {
		return getLesson();
	}
	
	@Override
	public String toString(){
		return super.toString()+getLesson();
	}
	
	@Override
	public JSONObject toJSon() throws DomainException {
		JSONObject output = super.toJSon();
		JsonKeysDictionary.toStringItem(output, JsonKeysDictionary.JSON_KEY_LEARN_LESSON, getLesson());
		return output;		
	}
	
	@Override
	public boolean equals(Object obj) {
		boolean gelijk = false;
		if(obj instanceof Learn){
			Learn l = (Learn)(obj);
			if(super.equals(l) && 				
				l.getLesson().equals(this.getLesson())){
				gelijk = true;
			}
		}		
		return gelijk;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((lesson == null) ? 0 : lesson.hashCode());
		return result;
	}

	@Override
	public int compareTo(Entry t) {
		int r = super.compareTo(t);
		if(r == 0) {
			Learn o = (Learn)t; 
			// CCE not possible because of super.compareTo(t)
			return this.getLesson().compareTo(o.getLesson());
		} else {
			return r;
		}
	}
}